# -*- coding: utf-8 -*-
# @Time     : 2023/12/9 21:44
# @Author   : JustFly
# @File     : channel_logic.py
# @Software : PyCharm


"""
# 总处理逻辑之一
处理 频道-聊天室 类型的逻辑
"""

from menu import keyword_menu
import re
from botpy import logger
from common.scripts import get_datetime
from menu import re_menu


def func(message):
    # print(message)
    ########################### 打印日志 ##############################
    raw_msg = re.sub(r'<@!\d+> ', "", message.content)
    raw_msg = re.sub(r'<@!\d+>', "", raw_msg)
    _log_raw_msg(message, raw_msg)
    ########################### 定义变量 ##############################
    res_msg = ""
    ########################### 关键词匹配 ############################
    menu_dict = keyword_menu.get_menu()
    logic_func = menu_dict.get(raw_msg)
    if logic_func:
        # 调用对应函数处理该消息
        res_msg = logic_func(message)
        _log_res_msg(message, res_msg)
        return res_msg
    ########################## re正则 关键词匹配 ##########################
    re_logic_func = re_menu.get_re_menu(message.content)
    if re_logic_func:
        res_msg = re_logic_func(message)
        _log_res_msg(message, res_msg)
        return res_msg

    ######################### AI 聊天保底 ############################
    # 群消息
    # if report_data['message_type'] == 'group' and report_data['sub_type'] == 'normal':
    #     return False
    # 若没有匹配到指令 AI 聊天保底
    # if about_money.deduct_money(report_data['sender']['user_id'], 0.5):
    #     res_msg = api_ai_chat.func(message)
    # else:
    #     res_msg = chongzhi_info
    # send_msg.func(report_data, res_msg)
    # return True
    if res_msg == "":
        res_msg = raw_msg
        _log_res_msg(message, res_msg)
        return res_msg

def _log_raw_msg(message, raw_msg):
    logger.info(
        f"【{get_datetime.func()}】频道-聊天室 的{message.member.nick}({message.author.id})发来一条@消息：{raw_msg}")

def _log_res_msg(message, res_msg):
    logger.info(f"【{get_datetime.func()}】回复 频道-聊天室 的{message.member.nick}({message.author.id})：{res_msg}")




